package apiday06.thread;

public class Bank {
    //取钱方法
    public synchronized boolean getMoney(int money){
        //查询账户余额
        int account = getAccount();
        //判断余额是否足够
        if(account>=money){
            account-=money;
            Thread.yield();
            saveAccount(account);
            return true;
        }
        return  false;
    }

    //账户余额
    private int account = 20000;
    //重新记账方法
    public int getAccount(){
        return account;
    }
    //查询余额方法
    public void saveAccount(int account){
         this.account = account;
    }
}
